package com.shanghai.shanghaielectric.UI.refreshView;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.shanghai.shanghaielectric.Model.ReportDateModel;
import com.shanghai.shanghaielectric.R;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import shanghaielectric_lib.Utils.DateUtil;

import static shanghaielectric_lib.Utils.DateUtil.dateToString_yy_MM_dd;


/**
 * Created by wnw on 16-5-26.
 */
public class MyAdapter_report extends RecyclerView.Adapter<RecyclerView.ViewHolder> {


    //定义一个集合，接收从Activity中传递过来的数据和上下文
    private List<ReportDateModel> mList;
    private Context mContext;

    public MyAdapter_report(Context context, List<ReportDateModel> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View layout = LayoutInflater.from(mContext).inflate(R.layout.report_item, parent, false);
        return new MyHolder(layout);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (holder instanceof MyHolder) {
            long id = mList.get(position).getId();


            ((MyHolder) holder).tv_id.setText(position + 1 + "");
            ((MyHolder) holder).tv_date.setText(dateToString_yy_MM_dd(mList.get(position).getDate()));
//
            ((MyHolder) holder).tv_date_systemPF_Max_All.setText(DateUtil.dateToString_HH_mm_ss(mList.get(position).getDate_systemPF_Max_All()));
            ((MyHolder) holder).tv_date_systemPF_Min_All.setText(DateUtil.dateToString_HH_mm_ss(mList.get(position).getDate_systemPF_Min_All()));

            ((MyHolder) holder).tv_systemPF_Max_All.setText(String.valueOf(mList.get(position).getSystemPF_Max_All()));
            ((MyHolder) holder).tv_systemPF_Min_All.setText(String.valueOf(mList.get(position).getSystemPF_Min_All()));
            ((MyHolder) holder).tv_systemPF_AVG_All.setText(String.valueOf(mList.get(position).getSystemPF_AVG_All()));

            ((MyHolder) holder).tv_systemPF_Max_A.setText(String.valueOf(mList.get(position).getSystemPF_Max_A()));
            ((MyHolder) holder).tv_systemPF_Max_B.setText(String.valueOf(mList.get(position).getSystemPF_Max_B()));
            ((MyHolder) holder).tv_systemPF_Max_C.setText(String.valueOf(mList.get(position).getSystemPF_Max_C()));

            ((MyHolder) holder).tv_systemPF_Min_A.setText(String.valueOf(mList.get(position).getSystemPF_Min_A()));
            ((MyHolder) holder).tv_systemPF_Min_B.setText(String.valueOf(mList.get(position).getSystemPF_Min_B()));
            ((MyHolder) holder).tv_systemPF_Min_C.setText(String.valueOf(mList.get(position).getSystemPF_Min_C()));

            ((MyHolder) holder).tv_systemPF_AVG_A.setText(String.valueOf(mList.get(position).getSystemPF_AVG_A()));
            ((MyHolder) holder).tv_systemPF_AVG_B.setText(String.valueOf(mList.get(position).getSystemPF_AVG_B()));
            ((MyHolder) holder).tv_systemPF_AVG_C.setText(String.valueOf(mList.get(position).getSystemPF_AVG_C()));

            ((MyHolder) holder).tv_loadPF_Max_A.setText(String.valueOf(mList.get(position).getLoadPF_Max_A()));
            ((MyHolder) holder).tv_loadPF_Max_B.setText(String.valueOf(mList.get(position).getLoadPF_Max_B()));
            ((MyHolder) holder).tv_loadPF_Max_C.setText(String.valueOf(mList.get(position).getLoadPF_Max_C()));
            ((MyHolder) holder).tv_loadPF_Min_A.setText(String.valueOf(mList.get(position).getLoadPF_Min_A()));
            ((MyHolder) holder).tv_loadPF_Min_B.setText(String.valueOf(mList.get(position).getLoadPF_Min_B()));
            ((MyHolder) holder).tv_loadPF_Min_C.setText(String.valueOf(mList.get(position).getLoadPF_Min_C()));
            ((MyHolder) holder).tv_loadPF_AVG_A.setText(String.valueOf(mList.get(position).getLoadPF_AVG_A()));
            ((MyHolder) holder).tv_loadPF_AVG_B.setText(String.valueOf(mList.get(position).getLoadPF_AVG_B()));
            ((MyHolder) holder).tv_loadPF_AVG_C.setText(String.valueOf(mList.get(position).getLoadPF_AVG_C()));

            ((MyHolder) holder).tv_systemActivePower_Max_A.setText(String.valueOf(mList.get(position).getSystemActivePower_Max_A()));
            ((MyHolder) holder).tv_systemActivePower_Max_B.setText(String.valueOf(mList.get(position).getSystemActivePower_Max_B()));
            ((MyHolder) holder).tv_systemActivePower_Max_C.setText(String.valueOf(mList.get(position).getSystemActivePower_Max_C()));


            ((MyHolder) holder).tv_systemActivePower_Min_A.setText(String.valueOf(mList.get(position).getSystemActivePower_Min_A()));
            ((MyHolder) holder).tv_systemActivePower_Min_B.setText(String.valueOf(mList.get(position).getSystemActivePower_Min_B()));
            ((MyHolder) holder).tv_systemActivePower_Min_C.setText(String.valueOf(mList.get(position).getSystemActivePower_Min_C()));

            ((MyHolder) holder).tv_systemActivePower_AVG_A.setText(String.valueOf(mList.get(position).getSystemActivePower_AVG_A()));
            ((MyHolder) holder).tv_systemActivePower_AVG_B.setText(String.valueOf(mList.get(position).getSystemActivePower_AVG_B()));
            ((MyHolder) holder).tv_systemActivePower_AVG_C.setText(String.valueOf(mList.get(position).getSystemActivePower_AVG_C()));


            ((MyHolder) holder).tv_systemReActivePower_Max_A.setText(String.valueOf(mList.get(position).getSystemReActivePower_Max_A()));
            ((MyHolder) holder).tv_systemReActivePower_Max_B.setText(String.valueOf(mList.get(position).getSystemReActivePower_Max_B()));
            ((MyHolder) holder).tv_systemReActivePower_Max_C.setText(String.valueOf(mList.get(position).getSystemReActivePower_Max_C()));

            ((MyHolder) holder).tv_systemReActivePower_Min_A.setText(String.valueOf(mList.get(position).getSystemReActivePower_Min_A()));
            ((MyHolder) holder).tv_systemReActivePower_Min_B.setText(String.valueOf(mList.get(position).getSystemReActivePower_Min_B()));
            ((MyHolder) holder).tv_systemReActivePower_Min_C.setText(String.valueOf(mList.get(position).getSystemReActivePower_Min_C()));


            ((MyHolder) holder).tv_systemReActivePower_AVG_A.setText(String.valueOf(mList.get(position).getSystemReActivePower_AVG_A()));
            ((MyHolder) holder).tv_systemReActivePower_AVG_B.setText(String.valueOf(mList.get(position).getSystemReActivePower_AVG_B()));
            ((MyHolder) holder).tv_systemReActivePower_AVG_C.setText(String.valueOf(mList.get(position).getSystemReActivePower_AVG_C()));

            ((MyHolder) holder).tv_systemEvent.setText(String.valueOf(mList.get(position).getSystemEvent()));

        }
    }

    class MyHolder extends RecyclerView.ViewHolder {
        TextView tv_id;
        TextView tv_date;

        TextView tv_date_systemPF_Max_All;
        TextView tv_date_systemPF_Min_All;

        TextView tv_systemPF_Max_All;
        TextView tv_systemPF_Min_All;
        TextView tv_systemPF_AVG_All;

        TextView tv_systemPF_Max_A;
        TextView tv_systemPF_Max_B;
        TextView tv_systemPF_Max_C;

        TextView tv_systemPF_Min_A;
        TextView tv_systemPF_Min_B;
        TextView tv_systemPF_Min_C;

        TextView tv_systemPF_AVG_A;
        TextView tv_systemPF_AVG_B;
        TextView tv_systemPF_AVG_C;

        TextView tv_loadPF_Max_A;
        TextView tv_loadPF_Max_B;
        TextView tv_loadPF_Max_C;

        TextView tv_loadPF_Min_A;
        TextView tv_loadPF_Min_B;
        TextView tv_loadPF_Min_C;

        TextView tv_loadPF_AVG_A;
        TextView tv_loadPF_AVG_B;
        TextView tv_loadPF_AVG_C;

        TextView tv_systemActivePower_Max_A;
        TextView tv_systemActivePower_Max_B;
        TextView tv_systemActivePower_Max_C;
        TextView tv_systemActivePower_Min_A;
        TextView tv_systemActivePower_Min_B;
        TextView tv_systemActivePower_Min_C;
        TextView tv_systemActivePower_AVG_A;
        TextView tv_systemActivePower_AVG_B;
        TextView tv_systemActivePower_AVG_C;

        TextView tv_systemReActivePower_Max_A;
        TextView tv_systemReActivePower_Max_B;
        TextView tv_systemReActivePower_Max_C;
        TextView tv_systemReActivePower_Min_A;
        TextView tv_systemReActivePower_Min_B;
        TextView tv_systemReActivePower_Min_C;
        TextView tv_systemReActivePower_AVG_A;
        TextView tv_systemReActivePower_AVG_B;
        TextView tv_systemReActivePower_AVG_C;
        TextView tv_systemEvent;// 1 表示 今日有故障发生   0 表示无


        public MyHolder(View itemView) {
            super(itemView);
            tv_id = (TextView) itemView.findViewById(R.id.item_id);
            tv_date = (TextView) itemView.findViewById(R.id.item_Date);

            tv_date_systemPF_Max_All = (TextView) itemView.findViewById(R.id.item_date_system_PF_max_all);
            tv_date_systemPF_Min_All = (TextView) itemView.findViewById(R.id.item_date_system_PF_min_all);

            tv_systemPF_Max_All = (TextView) itemView.findViewById(R.id.item_system_PF_max_all);
            tv_systemPF_Min_All = (TextView) itemView.findViewById(R.id.item_system_PF_min_all);
            tv_systemPF_AVG_All = (TextView) itemView.findViewById(R.id.item_system_PF_AVG_all);

            tv_systemPF_Max_A = (TextView) itemView.findViewById(R.id.item_system_PF_A_max);
            tv_systemPF_Max_B = (TextView) itemView.findViewById(R.id.item_system_PF_B_max);
            tv_systemPF_Max_C = (TextView) itemView.findViewById(R.id.item_system_PF_C_max);

            tv_systemPF_Min_A = (TextView) itemView.findViewById(R.id.item_system_PF_A_min);
            tv_systemPF_Min_B = (TextView) itemView.findViewById(R.id.item_system_PF_B_min);
            tv_systemPF_Min_C = (TextView) itemView.findViewById(R.id.item_system_PF_C_min);

            tv_systemPF_AVG_A = (TextView) itemView.findViewById(R.id.item_system_PF_A_avg);
            tv_systemPF_AVG_B = (TextView) itemView.findViewById(R.id.item_system_PF_B_avg);
            tv_systemPF_AVG_C = (TextView) itemView.findViewById(R.id.item_system_PF_C_avg);

            tv_loadPF_Max_A = (TextView) itemView.findViewById(R.id.item_load_PF_A_max);
            tv_loadPF_Max_B = (TextView) itemView.findViewById(R.id.item_load_PF_B_max);
            tv_loadPF_Max_C = (TextView) itemView.findViewById(R.id.item_load_PF_C_max);

            tv_loadPF_Min_A = (TextView) itemView.findViewById(R.id.item_load_PF_A_min);
            tv_loadPF_Min_B = (TextView) itemView.findViewById(R.id.item_load_PF_B_min);
            tv_loadPF_Min_C = (TextView) itemView.findViewById(R.id.item_load_PF_C_min);

            tv_loadPF_AVG_A = (TextView) itemView.findViewById(R.id.item_load_PF_A_avg);
            tv_loadPF_AVG_B = (TextView) itemView.findViewById(R.id.item_load_PF_B_avg);
            tv_loadPF_AVG_C = (TextView) itemView.findViewById(R.id.item_load_PF_C_avg);

            tv_systemActivePower_Max_A = (TextView) itemView.findViewById(R.id.item_system_activePower_A_max);
            tv_systemActivePower_Max_B = (TextView) itemView.findViewById(R.id.item_system_activePower_B_max);
            tv_systemActivePower_Max_C = (TextView) itemView.findViewById(R.id.item_system_activePower_C_max);

            tv_systemActivePower_Min_A = (TextView) itemView.findViewById(R.id.item_system_activePower_A_min);
            tv_systemActivePower_Min_B = (TextView) itemView.findViewById(R.id.item_system_activePower_B_min);
            tv_systemActivePower_Min_C = (TextView) itemView.findViewById(R.id.item_system_activePower_C_min);

            tv_systemActivePower_AVG_A = (TextView) itemView.findViewById(R.id.item_system_activePower_A_avg);
            tv_systemActivePower_AVG_B = (TextView) itemView.findViewById(R.id.item_system_activePower_B_avg);
            tv_systemActivePower_AVG_C = (TextView) itemView.findViewById(R.id.item_system_activePower_C_avg);

            tv_systemReActivePower_Max_A = (TextView) itemView.findViewById(R.id.item_system_ReactivePower_A_max);
            tv_systemReActivePower_Max_B = (TextView) itemView.findViewById(R.id.item_system_ReactivePower_B_max);
            tv_systemReActivePower_Max_C = (TextView) itemView.findViewById(R.id.item_system_ReactivePower_C_max);

            tv_systemReActivePower_Min_A = (TextView) itemView.findViewById(R.id.item_system_ReactivePower_A_min);
            tv_systemReActivePower_Min_B = (TextView) itemView.findViewById(R.id.item_system_ReactivePower_B_min);
            tv_systemReActivePower_Min_C = (TextView) itemView.findViewById(R.id.item_system_ReactivePower_C_min);

            tv_systemReActivePower_AVG_A = (TextView) itemView.findViewById(R.id.item_system_ReactivePower_A_avg);
            tv_systemReActivePower_AVG_B = (TextView) itemView.findViewById(R.id.item_system_ReactivePower_B_avg);
            tv_systemReActivePower_AVG_C = (TextView) itemView.findViewById(R.id.item_system_ReactivePower_C_avg);

            tv_systemEvent = (TextView) itemView.findViewById(R.id.item_system_runningEvent);

        }
    }

//    public void setData(ErrorInfoModel errorInfoModel){
//        mList.add(0,errorInfoModel);
//    }
}
